package cn.tedu._04mybatis.mapper;

import cn.tedu._04mybatis.pojo.entity.Weibo;
import cn.tedu._04mybatis.pojo.vo.WeiboMapVO4;
import cn.tedu._04mybatis.pojo.vo.WeiboVO3;
import cn.tedu._04mybatis.pojo.vo.WeiboVo1;
import cn.tedu._04mybatis.pojo.vo.WeiboVo2;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WeiboMapper {
    /** 1.在微博表中插入1条数据;
     接口方法的返回值类型:
     1.写操作[增删改]: int类型,表示受影响的数据条数;
     2.查询操作:看具体查出来的数据;
     */
    //@Insert("INSERT INTO weibo(content,created,user_id) VALUES (#{content}, #{created}, #{userId})")
    void insertWeibo(Weibo weibo);
    /**
     * 2.根据微博id删除指定的1条微博;
     */
    //@Delete("DELETE FROM weibo WHERE id=#{wid}")
    int deleteWeiboById(Long wid);
    /**
     * 3.根据微博ID更新指定微博的信息;
     * UPDATE weibo SET content=#{content},created=#{created},user_id=#{userId} WHERE id=#{id}
     */
    //@Update("UPDATE weibo SET content=#{content}, created=#{created}, user_id=#{userId} WHERE id=#{id}")
    //@Update("UPDATE weibo SET content=#{content},created=#{created},user_id=#{userId} WHERE id=#{id}")
    int updateWeiboById(Weibo weibo);
    /**
     * 4.单条数据全字段查询;
     *   根据微博id查询指定微博的所有信息: id、content、created、user_id
     *   SELECT id, content, created, user_id FROM weibo WHERE id=#{id}
     * 2.框架做的事情
     *   PreparedStatement ps = connection.prepareStatement("SELECT ... WHERE id=?");
     *   ps.setInt(1, 200L);
     *   ResultSet rs = ps.executeQuery();
     *   if (rs.next()){
     *       int id = rs.getInt("id);
     *       String content = rs.getString("content");
     *       ...
     *
     *       Weibo weibo = new Weibo();
     *       weibo.setId(id);
     *       weibo.setContent(content);
     *       ... ...
     *   }
     */
    //@Select("SELECT id,content,created,user_id userId FROM weibo WHERE id=#{id}")
    Weibo selectWeiboById(Long id);
    /**
     * 5.多条数据全字段查询;
     *   根据用户的id查询该用户发的所有的微博信息: id content created user_id
     */
    //@Select("SELECT id,content,created,user_id userId FROM weibo WHERE user_id=#{uid}")
    List<Weibo>selectWeiboByUserId(Long uid);
    /**
     * 6.单条数据部分字段查询;
     *   根据微博id查询该条微博的内容和发布时间: content  created
     */
    //@Select("SELECT content,created FROM weibo WHERE id=#{wid}")
    WeiboVo1 selectWeiboVo1(Long wid);
    /**
     * 7.查询所有微博的内容和用户id: content  user_id
     *   第1步:创建VO类 WeiboVO2;
     *   第2步:定义接口方法,写SQL;
     *   第3步:测试;
     */
    //@Select("SELECT content,user_id userId FROM weibo")
    List<WeiboVo2>selectWeiboVo2();

    /**
     * 8.统计微博的条数;
     *   SELECT COUNT(*) FROM weibo
     */
    int selectCount();

    /**
     * 9.动态更新;
     *   根据微博的id动态修改该条微博的信息;
     */
    int dynamicUpdateWeiboById(Weibo weibo);

    /**
     * 10.动态删除:数组方式
     * DELETE FROM weibo WHERE id IN(201L,203L,204L)
     */
    int dynamicDeleteWeiboByIds(Long[] ids);

    /**
     * * 11.动态删除:集合方式
     *      * DELETE FROM weibo WHERE id IN(201L,203L,204L)
     */
    int dynamicDeleteWeiboByIds2(List<Long> ids);

    /**
     * 12..根据微博id查询该条微博的id、内容和用户id: id content user_id
     *
     */
    WeiboVO3 selectResultMap1(Long id);

    /**
     * 13.
     */
    WeiboMapVO4 selectResultMap2(Long uid);
}
